<template>
  <el-dialog :title="$t('btn.Details')" v-model="visible" width="60%" >
    <splitpanes horizontal>
      <pane size="50">
        <div class="layout-padding-auto layout-padding-view">
          <!--查询结果的列表-->
          <el-table :data="state.dataList" highlight-current-row
                    v-loading="state.loading" border style="width: 100%;height: 100%"
                    :cell-style="tableStyle.cellStyle" stripe :header-cell-style="tableStyle.headerCellStyle"
                    @row-click="clickRow"
                    @selection-change="selectionChangeHandle">
            <el-table-column prop="productionLineCode" width="120" :label="$t('iot.productionLineCode')"/>
            <el-table-column prop="processName" width="120" :label="$t('iot.processName')"/>
            <el-table-column prop="checkType" width="120" :label="$t('qms.detectionClassCode')"/>
            <el-table-column prop="pqcCount" width="120" :label="$t('qms.numberOfInspection')"/>
            <el-table-column prop="destroyStatus" width="120" :label="$t('qms.destroyTestResult')"/>
            <el-table-column prop="starCheckTime" width="160" :label="$t('qms.breakTheStartInspectionTime')"/>
            <el-table-column prop="endCheckTime" width="160" :label="$t('qms.breakTheEndCheckTime')"/>
            <el-table-column prop="noDestroyStatus" width="160" :label="$t('qms.non-destructiveTestResults')"/>
            <el-table-column prop="fphStarCheckTime" width="160" :label="$t('qms.non-destructiveStartInspectionTime')"/>
            <el-table-column prop="fphEndCheckTime" width="160" :label="$t('qms.non-destructiveEndOfInspectionTime')"/>
            <el-table-column prop="shiftCode" width="120" :label="$t('qms.shiftCode')"/>
            <el-table-column prop="checkDate" width="120" :label="$t('qms.detectionTime')"/>
          </el-table>
        </div>
      </pane>
      <pane size="50">
        <div class="layout-padding-auto layout-padding-view">
          <el-tabs model-value="first">
            <el-tab-pane name="first">
              <template #label>
                <el-icon><calendar/></el-icon>
                <span class="ml-0.5"> {{$t('qms.detail')}} </span>
              </template>
            </el-tab-pane>
          </el-tabs>
          <detial ref="locationRef"/>
        </div>
      </pane>
    </splitpanes>
  </el-dialog>

</template>

<script setup lang="ts">

import {BasicTableProps, useTable} from "/@/hooks/table";
import detial from "./pqcDetial.vue";
import {getPqcPageSet} from "/@/api/platform/qms/qmsCheckReport";
import {mesProcessLine, mesProcessPage} from "/@/api/platform/qms/qmsRelationH";

// 搜索变量
const locationRef = ref()
const processList = ref()
const lineList = ref()
const visible = ref(false)

const openDialog = (row:any) =>{
  state.queryForm.id = row.pqcId
  getDataList()
  visible.value = true
  locationRef.value.query(row.pqcId)
}

// 仓库表格的配置
const state: BasicTableProps = reactive<BasicTableProps>({
  queryForm: {},
  pageList: getPqcPageSet
})

const getProcessList = (query: any) => {
  mesProcessPage({
    "queryWord": query
  }).then((res: any) => {
    if (res.code == 0) {
      processList.value = res.data.records
    }
  })
}

const changeProcessList = (e) => {
  state.queryForm.processCode = e.processCode
  state.queryForm.processName = e.processName
  state.queryForm.processId = e.id
  mesProcessLine({
    "id": e.id
  }).then((res: any) => {
    if (res.code == 0) {
      lineList.value = res.data
    }
  })
}


//  table hook
const {
  tableStyle,
  getDataList,
  sizeChangeHandle,
  currentChangeHandle
} = useTable(state)

// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)

// 多选事件
const selectionChangeHandle = (objs: { id: string }[]) => {
  selectObjs.value = objs.map(({id}) => id);
  multiple.value = !objs.length;
};

//时间点击
const changeCheckTime = (data) => {
  state.queryForm.checkStartTime = data[0]
  state.queryForm.checkEndTime = data[1]
}


// 点击行的时候触发
const clickRow = (row: any) => {
  locationRef.value.query(row.id)
}

// 清空搜索条件
const resetQuery = () => {
  // 清空搜索条件
  // state.queryForm = {"checkStartTime":formatDate(new Date()),"checkEndTime":formatDate(new Date())}
  state.queryForm = {}
  // 清空多选
  selectObjs.value = []
  getDataList()
}

// 暴露变量
defineExpose({
  openDialog
});
</script>
